import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let defaultcity = '上海'
try {
  if (localStorage.city) {
    defaultcity = localStorage.city
  }
} catch (e) {

}

export default new Vuex.Store({
  state: {
    city: defaultcity || '上海'
  },
  actions: {
    changeCity (ctx, cityname) {
      console.log(cityname)
      ctx.commit('changeCity', cityname)
    }
  },
  mutations: {
    changeCity (state, city) {
      state.city = city
      localStorage.city = city
    }
  }
})
